package com.project.service;

import com.project.dao.ResourceMapper;
import com.project.entity.Resource;
import com.project.service.base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: TateBrown
 * @date: 2018/5/25 19:37
 * @param:
 * @return:
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ResourceServiceImpl extends BaseService implements ResourceService {
    @Autowired
    private RoleResourceService roleResourceService;
    @Autowired
    private ResourceMapper resourceMapper;

    @Override
    public List<Resource> findByCondition(Resource resource){


        return resourceMapper.selectByCondition(resource);
    }

    @Override
    public int addOne(Resource resource){


        return  resourceMapper.insertSelective(resource);
    }

    @Override
    public int modifyOneById(Resource resource){

        return resourceMapper.updateByPrimaryKeySelective(resource);
    }

    @Override
    public int removeOneById(int id){

        //删除资源
        resourceMapper.deleteByPrimaryKey(id);
        //删除角色资源表中的相应记录
        roleResourceService.deleteByResourceId(id);

        return 1;
    }

    @Override
    public Resource findOneById(int id){

        return  resourceMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Resource> findByIds(List idList){

        return resourceMapper.selectByIds(idList);
    }
}
